package LeetCode.month01.day15;

import java.util.Arrays;

public class No198 {
    public static void main(String[] args) {
        int[] nums =  new int[]{2,1,1,2};
        System.out.println(rob(nums));
    }
    //dp[][]
    //
    public static int rob(int[] nums) {
        if(nums.length==1) return nums[0];
        int[][] dp = new int[nums.length][2];
        int max = Math.max(nums[0],nums[1]);
        dp[0][0]=nums[0];
        dp[0][1]=0;
        for (int i = 1; i < nums.length; i++) {
            dp[i][0] = dp[i-1][1]+nums[i];
            dp[i][1] = Math.max(dp[i-1][0],dp[i-1][1]);
            max =Math.max(dp[i][0],dp[i][1]);
        }
//        for (int i = 0; i < nums.length; i++) {
//            System.out.println(Arrays.toString(dp[i]));
//        }
        return max;
    }
}
